<template>
  <div class="w">
    <div class="w-top">
      <h3 class="w-top-top">
        <span>{{cat}}</span>
        <a class="xuanze" href="javascript:;" @click="xuanze">
          <i>选择分类</i>
          <em></em>
        </a>
        <div class="posi-box" ref="box">
          <div class="post-box-top">
            <a href="">全部风格</a>
          </div>
          <div class="xuanze-box">
            <dl>
              <dt class="dl-dt">
                <i></i>
                <span>语种</span>
              </dt>
              <dd>
                <template v-for="(item, index) in gedanArr.sub" :key="index">
                  <a
                    href="javascript:;"
                    v-if="item.category == 0"
                    @click="tiaoz(item.name)"
                    >{{ item.name }}</a
                  >
                </template>
              </dd>
            </dl>
            <dl>
              <dt class="dl-dt">
                <i></i>
                <span>风格</span>
              </dt>
              <dd>
                <template v-for="(item, index) in gedanArr.sub" :key="index">
                  <a
                    href="javascript:;"
                    v-if="item.category == 1"
                    @click="tiaoz(item.name)"
                    >{{ item.name }}</a
                  >
                </template>
              </dd>
            </dl>
            <dl>
              <dt class="dl-dt">
                <i></i>
                <span>场景</span>
              </dt>
              <dd>
                <template v-for="(item, index) in gedanArr.sub" :key="index">
                  <a
                    href="javascript:;"
                    v-if="item.category == 2"
                    @click="tiaoz(item.name)"
                    >{{ item.name }}</a
                  >
                </template>
              </dd>
            </dl>
            <dl>
              <dt class="dl-dt">
                <i></i>
                <span>情感</span>
              </dt>
              <dd>
                <template v-for="(item, index) in gedanArr.sub" :key="index">
                  <a
                    href="javascript:;"
                    v-if="item.category == 3"
                    @click="tiaoz(item.name)"
                    >{{ item.name }}</a
                  >
                </template>
              </dd>
            </dl>
            <dl>
              <dt class="dl-dt">
                <i></i>
                <span>主题</span>
              </dt>
              <dd>
                <template v-for="(item, index) in gedanArr.sub" :key="index">
                  <a
                    href="javascript:;"
                    v-if="item.category == 4"
                    @click="tiaoz(item.name)"
                    >{{ item.name }}</a
                  >
                </template>
              </dd>
            </dl>
          </div>
        </div>
      </h3>
      <a class="hot" href="">热门</a>
    </div>
    <div class="w-content">
      <gedan-list :gedan="gedan"></gedan-list>
    </div>
    <el-pagination
      v-model:currentPage="currentPage"
      :page-sizes="[70, 140, 210, 280]"
      :page-size="70"
      layout="total, sizes, prev, pager, next, jumper"
      :total="gedan.total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    >
    </el-pagination>
  </div>
</template>

<script>
import { geDanFenL, getadsa } from "../api/gedan";
import GedanList from "../components/gedanList.vue";

import list from "../components/list.vue";
export default {
  components: { list, GedanList },
  data() {
    return {
      gedanArr: [],
      a: false,
      gedan: [],
      currentPage: 1, //当前页数
      limit:70,
      cat:"全部"
    };
  },
  async created() {
    let res = await geDanFenL();
    console.log(res);
    this.gedanArr = res;

    let gedan = await getadsa();
    console.log("gendaohnfgjaenbg-----", gedan);
    this.gedan = gedan;
  },
  methods: {
    async getfenye(){
      let offset  = (this.currentPage-1) * this.limit
      let params = {
        limit:this.limit,
        cat:this.cat,
        offset  //（当前页-1）* 每页条数
      }
      let res = await getadsa(params);
      console.log(res);
      this.gedan = res
    },
    handleSizeChange(val) {
      console.log(`每页条数${val}`);
      this.limit = val
      this.getfenye()
    },
    handleCurrentChange(val) {
      console.log(`当前页码: ${val}`);
      this.currentPage = val
      this.getfenye()
    },
    xuanze() {
      this.a = !this.a;
      console.log(this.a);
      this.$refs.box.style =
        this.a == true ? "display: block;" : "display: none;";
    },
    async tiaoz(cat) {
      console.log(cat);
      this.a = !this.a;
      this.$refs.box.style =
      this.a == true ? "display: block;" : "display: none;";
      this.cat  = cat
      let params = { cat:this.cat };
      let gedan = await getadsa(params);
      console.log("211111111", gedan);
      this.gedan = "";
      this.gedan = gedan;
    },
  },
};
</script>

<style lang="less" scoped>
dd a {
  font-weight: 400;
  margin: 0px 5px;
}
a {
  color: #333;
  font-size: 12px;
}
dl {
  display: flex;
  width: 700px;
  align-items: center;
  padding: 16px 15px 0px;
}
.dl-dt {
  margin-right: 10px;
  margin-top: 10px;
}
.dl-dt > span {
  display: inline-block;
  font-size: 12px !important;
  font-weight: 700;
  width: 30px;
}
dd {
  display: flex;
  align-items: center;
  margin-top: 5px;
  width: 605px;
  flex-wrap: wrap;
  a {
    margin-top: 10px;
  }
}
.posi-box {
  position: absolute;
  padding: 20px;
  border: 1px solid #d3d3d3;
  border-radius: 10px;
  background-color: #fff;
  display: none;
}
.post-box-top {
  border-bottom: 1px solid #d3d3d3;
  width: 772px;
}
.posi-box > .post-box-top > a {
  display: block;
  width: 75px;
  height: 26px;
  text-align: center;
  line-height: 26px;
  border: 1px solid #c4c4c4;
  border-radius: 3px;
  margin-top: 15px;
  margin-bottom: 20px;
}
.w {
  width: 982px;
  margin: auto;
  padding: 40px;
  border: 1px solid #d3d3d3;
}
.w-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 7px;
  border-bottom: 2px solid #c20c0c;
}
.w-top-top {
  position: relative;
  span {
    font-size: 24px;
    font-weight: normal;
  }
  .xuanze {
    font-size: 12px;
    font-weight: normal;
    margin: 2px 0 0 12px;
    display: inline-block;
    height: 31px;
    width: 86px;
    line-height: 31px;
    overflow: hidden;
    vertical-align: top;
    text-align: center;
    border: 1px solid #c4c4c4;
    border-radius: 5px;
    i {
      font-style: normal;
      color: #0c73c2;
    }
    em {
      display: inline-block;
      background: url("../imgs/icon.png") no-repeat -65px -520px;
      width: 11px;
      height: 8px;
      margin-left: 3px;
    }
  }
}
.hot {
  width: 46px;
  height: 29px;
  line-height: 29px;
  text-align: center;
  color: #fff;
  display: inline-block;
  background-color: #c60c0c;
  font-size: 12px;
  border: 1px solid #a80909;
  border-radius: 3px;
}
</style>